#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>

int main()
{
    int ret = mkfifo("./test.fifo", 0664);
    if (ret < 0 && errno != EEXIST) {
        perror("mkfifo error");
        return -1;
    }

    int fd = open("./test.fifo", O_WRONLY);
    if (fd < 0) {
        perror("open error");
        return -1;
    }
    printf("open success!!\n");
    int i = 0;
    while(1) {
        char buf[1024] = {0};
        sprintf(buf, "今天天气挺热的~！！+%d", i++);
        int ret = write(fd, buf, strlen(buf));
        if (ret < 0) {
            perror("write error");
            close(fd);
            return -1;
        }
        sleep(1);
    }
    close(fd);
    return 0;
}
